<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/include/common-base.jsp"%>
  <title>系统数据字典</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/plateform/left-project.jsp" %>
  <!-- left end-->



  <div class="content-wrapper">


    <!-- Main start -->
<section class="content">
      <div class="row">
        <div class="col-xs-12">

          <div class="box box-info">
            <div class="box-header">
               <h3 class="box-title"><i class="fa fa-search"></i> [<span id="title_sys_name"></span>]系统数据字典</h3>
				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
				</div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">

				<form id="searchForm" class="form-horizontal" action="javascript:;">
					<%--<input type="hidden" name="doCode" value="dictCateList"/>--%>
						<input type="hidden" name="pageName" value="dict-list"/>
						<input type="hidden" name="formName" value="searchForm"/>
						<input type="hidden" name="orderBy" value="dictDataCate.cate_ename asc"/>
						<input type="hidden" name="dictDataCate.w_sysEname" class="sysEname" value="default"/>
					<div class="form-group">
						<div class="col-sm-2 text-right"><label class="control-label" >科目名称：</label></div>
						<div class="col-sm-3">
							<input type="text" class="form-control clean"  name="dictDataCate.w_cateCname" value="" />
						</div>
						<div class="col-sm-2 text-right"><label class="control-label" >科目标识：</label></div>
						<div class="col-sm-3">
							<input type="text" class="form-control clean"  name="dictDataCate.w_cateEname" value="" />
						</div>
					</div>
					<center>
						<div class="box-footer clearfix">
							<button type="button" class="btn btn-success" onclick="getTableData();"><i class="fa fa-search"></i> 查询</button>&nbsp;&nbsp;
							<button  type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchForm');">重置 </button>
						</div>
					</center>
				</form>


            </div>
          </div>

			<div class="box box-success">
				<div class="box-header">
					<h3 class="box-title">数据字典列表 [共计<span id="dataListTotalCount">0</span>条数据]</h3>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-success" type="button" onclick="toAdd('parent');"><i class="fa fa-plus-circle"></i> 增加</button>
				</div>
				<!-- /.box-header -->
				<div class="box-body">
					<table id="example" class="table table-bordered " >
						<thead class="bg-success">
						<tr>
							<th>科目名称</th>
							<th>科目标识</th>
							<th>状态</th>
							<th>描述</th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody id="myList">
						</tbody>
					</table>
					<center>
						<ul id="pageList"></ul>
					</center>
				</div>
			</div>
        </div>
      </div>
    </section>

    <!-- Main end -->

    <div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="top:10%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">科目信息</font>&nbsp;</h4>
					</div>

					<div class="modal-body">
						<form class="form-horizontal" role="form" id="addForm" action="javascript:;">
							<input type="hidden" class="clean formToken" name="formToken" id="formToken" value="${formToken}"/>
							<%--<input type="" class="clean"  name="cateId" id="cateId" value="${item.cateId}"/>--%>
							<%--<input type="" class="clean"  name="oldCateEname" id="oldCateEname" value="${item.cateEname}"/>--%>
			    			<%--<input type="hidden" name="doCode" value="dictCateSave"/>--%>

							<input type="hidden" name="pageName" value="dict-list"/>
							<input type="hidden" name="formName" value="addForm"/>
							<input type="hidden" name="dictDataCate.cateStatus" value="1"/>
							<input type="hidden" name="dictDataCate.sysEname" data-name="dictDataCate.sysEname" class="sysEname" value=""/>
							<input type="hidden" class="clean" data-name="dictDataCate.cateId" name="dictDataCate.w_cateId"  value="${item.cateId}"/>

							 <div class="box-body">
			                <div class="form-group">
			                  <label  class="col-sm-4 control-label" >科目中文名称</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateCname"  name="dictDataCate.cateCname" data-name="dictDataCate.cateCname" required placeholder="必填项">
			                  </div>
			                </div>

			                <div class="form-group">
			                  <label class="col-sm-4 control-label">科目英文标识</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateEname" name="dictDataCate.cateEname" data-name="dictDataCate.cateEname" required placeholder="必填项">
			                  </div>
			                </div>

			                <div class="form-group">
			                  <label class="col-sm-4 control-label">描述</label>
			                  <div class="col-sm-6">
			                    <input type="text" class="form-control clean" id="cateRemark" name="dictDataCate.s_cateRemark" data-name="dictDataCate.cateRemark" placeholder="">
			                  </div>
			                </div>

			                <div class="form-group hidden">
			                  <label class="col-sm-4 control-label">状态</label>
			                  <div class="col-sm-6">
			                    <input type="radio" checked="checked" value="1" name="dictDataCate.cateStatus"> <i></i> 启用
                                <input type="radio" value="0" name="dictDataCate.cateStatus"> <i></i> 停用
			                  </div>
			                </div>

							 <div class="form-group">
								 <label class="col-sm-4 control-label">子级条目类型</label>
								 <div class="col-sm-6">
									 <select name="dictDataCate.viewType" class="form-control clean" style="width:200px;">
										 <option value="">--默认--</option>
										 <option value="1">三级联动</option>
										 <option value="2">树形结构</option>
									 </select>
								 </div>
							 </div>
			              </div>
			               <div class="box-footer">
			                <button type="button" class="btn btn-primary pull-left" onclick="mytools.closeModal('my_modal')">取消</button>
			                <button type="button" class="btn btn-primary pull-right" onclick="save('addForm');">提 交</button>
			              </div>
						</form>
					</div>


				</div>
				<!-- /.modal-content -->
			</div>
	</div>

	  <div class="modal fade" id="my_modal_dictItem_view" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog" style="min-height:400px;width:70%;">
			  <div class="modal-content">
				  <div class="modal-header">
					  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					  <h4 class="modal-title"><font color="red">[<span id="data-cname"></span>] 条目明细</font>&nbsp;</h4>
				  </div>
				  <div class="modal-body">
					  <form id="searchItemForm" class="form-horizontal" action="javascript:;">
						  <%--<input type="hidden" name="doCode" value="dictItemList"/><!-- ----- -->--%>
							  <input type="hidden" name="pageName" value="dict-list-default"/>
							  <input type="hidden" name="formName" value="searchItemForm"/>
							  <input type="hidden" name="dictDataItem.w_fatherId" value="0"/>
							  <input type="hidden" name="dictDataItem.w_cateEname" id="form_cateEname"/>
							  <input type="hidden" name="orderBy" value="dictDataItem.item_value asc"/>
							  <input type="hidden" name="viewType"/>
						  <div class="form-group">
							  <div class="col-sm-2 text-right"><label class="control-label" >条目名称：</label></div>
							  <div class="col-sm-3">
								  <input type="text" class="form-control clean"  name="dictDataItem.w_itemText" id="itemText" value="" />
							  </div>
							  <div class="col-sm-2 text-right"><label class="control-label" >条目值：</label></div>
							  <div class="col-sm-3">
								  <input type="text" class="form-control clean" name="dictDataItem.w_itemValue" id="itemValue" value="" />
							  </div>
						  </div>
						  <center>
							  <div class="box-footer clearfix">
								  <button type="button" class="btn btn-success" onclick="getDataItems();"><i class="fa fa-search"></i> 查询</button>&nbsp;&nbsp;
								  <button  type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchItemForm');">重置 </button>
							  </div>
						  </center>
					  </form>

					  <div class="box box-success">
						  <div class="box-header">
							  <h3 class="box-title">条目明细列表</h3>&nbsp;&nbsp;
							  <button class="btn btn-info" type="button" onclick="toItemAdd()">增加条目</button>
						  </div>
						  <!-- /.box-header -->
						  <div class="box-body">
							  <table id="tabItems" class="table table-bordered " >
								  <thead class="bg-success">
								  <tr>
									  <th>条目名称</th>
									  <th>条目标识</th>
									  <th>描述</th>
									  <th>操作</th>
								  </tr>
								  </thead>
								  <tbody id="dictItmes_body"> </tbody>
							  </table>
						  </div>
					  </div>
				  </div>
			  </div>
			  <!-- /.modal-content -->
		  </div>
	  </div>

	  <div class="modal fade" id="my_modal_item" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
			  <div class="modal-content">
				  <div class="modal-header">
					  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					  <h4 class="modal-title"><font color="red">条目信息</font>&nbsp;<font color="red" id="span_dataItemForm_father_title"></font></h4>
				  </div>
				  <div class="modal-body">
					  <form class="form-horizontal" role="form" id="dataItemForm" action="javascript:;">
						  <input type="hidden" name="formToken" class="formToken" id="dataItemForm_formToken" value="${formToken}"/>
						  <input type="hidden" name="pageName" value="dict-list-default"/>
						  <input type="hidden" name="formName" value="addItemForm"/>
						  <input type="hidden" name="dictDataItem.sysName" class="sysEname" value=""/>
						  <input type="hidden" name="dictDataItem.itemStatus" value="1"/>
						  <input type="hidden" name="dictDataItem.subCount" class="clean" data-name="dictDataItem.subCount"/>
						  <input type="hidden" name="dictDataItem.treeLevel" class="clean" data-name="dictDataItem.treeLevel"/>
						  <input type="hidden" name="dictDataItem.cateEname" class="clean" data-name="dictDataItem.cateEname" id="data-cateEname"/>
						  <input type="hidden" name="dictDataItem.fatherId" class="clean" id="data-fatherId" data-name="dictDataItem.fatherId" value="0"/>
						  <input type="hidden" name="dictDataItem.w_itemId" class="clean" data-name="dictDataItem.itemId" id="data-itemId" value=""/>
						  <div class="box-body">
							  <div class="form-group">
								  <label  class="col-sm-2 control-label">条目名称</label>
								  <div class="col-sm-8">
									  <input type="text" class="form-control clean" data-name="dictDataItem.itemText" name="dictDataItem.itemText" required placeholder="必填项">
								  </div>
							  </div>
							  <div class="form-group">
								  <label class="col-sm-2 control-label">条目标识</label>
								  <div class="col-sm-8">
									  <input type="text" class="form-control clean" data-name="dictDataItem.itemValue" name="dictDataItem.itemValue" required placeholder="英文或数字标识">
								  </div>
							  </div>
							  <div class="form-group">
								  <label class="col-sm-2 control-label">条目描述</label>
								  <div class="col-sm-8">
									  <input type="text" class="form-control clean" data-name="dictDataItem.itemRemark"  name="dictDataItem.s_itemRemark" placeholder="">
								  </div>
							  </div>
						  </div>
						  <div class="box-footer">
							  <button type="button" class="btn btn-primary pull-left" onclick="mytools.closeModal('my_modal_item');">取消</button>
							  <button type="button" class="btn btn-primary pull-right" onclick="saveItem('dataItemForm');">提 交</button>
						  </div>
					  </form>
				  </div>
			  </div>
			  <!-- /.modal-content -->
		  </div>
	  </div>

	  <script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id=<?=rows[i].cateId?> >
					<th style="display:none;"><?=rows[i].dictDataCate.cateId?></th>
					<td><?=rows[i].dictDataCate.cateCname?></td>
					<td><?=rows[i].dictDataCate.cateEname?></td>
					<td><?if("1"==rows[i].dictDataCate.cateStatus){?><font color=blue>启用</font>
                        <?}else{?><font color=red>停用</font><?}?>
                    </td>
					<td><?=rows[i].dictDataCate.cateRemark?></td>
					<td>
						<button class="btn btn-warning btn-xs" type="button" onclick="toEdit('<?=rows[i].dictDataCate.cateEname?>','<?=rows[i].dictDataCate.cateId?>')">修改</button>&nbsp;
						<button class="btn btn-danger btn-xs" type="button" onclick="del('<?=rows[i].dictDataCate.cateEname?>','<?=rows[i].dictDataCate.cateId?>')">删除</button>&nbsp;
						<button class="btn btn-primary btn-xs" type="button" onclick="itemTrees('<?=rows[i].dictDataCate.cateEname?>','<?=rows[i].dictDataCate.cateCname?>','<?=rows[i].dictDataCate.viewType?>')">条目明细</button>
                    </td>
				</tr>
     		<?}?>
		</script>

	  <script type="text/template" id="dataItemList">
		  <? for ( var i = 0; i < rows.length; i++) {?>
		  <tr id="<?=rows[i].dictDataItem.itemId?>" treeLevel="<?=rows[i].dictDataItem.treeLevel?>" fatherId="<?=rows[i].dictDataItem.fatherId?>">
			  <th style="display:none;"><?=rows[i].dictDataItem.itemId?></th>
			  <th style="display:none;"><?=rows[i].dictDataItem.treeLevel?></th>
			  <th style="display:none;"><?=rows[i].dictDataItem.fatherId?></th>
			  <td><?if(rows[i].dictDataItem.subCount>0){?>
				  <i class="fa fa-folder" onclick="getChildTableData('<?=rows[i].dictDataItem.itemId?>','<?=rows[i].dictDataItem.fullEname?>',this);">&nbsp;<?=rows[i].dictDataItem.itemText?></i>
				  <?} else{?>	<i class="fa fa-file"></i>&nbsp;<?=rows[i].dictDataItem.itemText?>
				  <?}?></td>
			  <td><?=rows[i].dictDataItem.itemValue?></td>
			  <td><?=rows[i].dictDataItem.itemRemark?></td>
			  <td>
				  <a href="javascript:void(0);" onclick="delItem('<?=rows[i].dictDataItem.itemId?>','<?=rows[i].dictDataItem.cateEname?>','<?=rows[i].dictDataItem.itemValue?>','<?=rows[i].dictDataItem.fatherId?>');">删除</a>&nbsp;
				  <a href="javascript:void(0);" onclick="toItemEdit('<?=rows[i].dictDataItem.itemId?>','<?=rows[i].dictDataItem.itemValue?>');">修改</a>&nbsp;
				  <?if(viewType=='1'||viewType=='2'){?>
				  		<a href="javascript:void(0);" onclick="toSubItemAdd('<?=rows[i].dictDataItem.itemId?>','<?=rows[i].dictDataItem.itemValue?>','<?=rows[i].dictDataItem.fullEname?>')">增加子条目</a>
				  <?}?>
			  </td>
		  </tr>
		  <?}?>
	  </script>

    <script>
var clickMenu= 'dict-list';
var id;
var cateEname;
var dictUrl = common_list_url+"?doCode=dictItemList";
var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
//$("#searchForm").find("input[name='dictDataCate.w_sysEname']").val(defSysEname);
var itemId;
$(function () {
    if (!strUtil.isNull(defSysEname)) {
        $(".sysEname").val(defSysEname);
        $("#title_sys_name").html(defSysEname);
	}

	getTableData();
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }  else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	    // id = $('tr.selected th').eq(0).html();
	    // cateEname = $('tr.selected td').eq(1).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );


});

//设置模态框隐藏事件钩子
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){
    mytools.cleanData("#addForm");
});

//设置模态框隐藏事件钩子
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){
	$.ajax({ type:'post',url:'${ctx}/sendPage/token?token=true', dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
		  $('.formToken').val(myData);
	  	}
	});
});


function getTableData(){
	$.ajax({url:common_list_url,
		type: "get",dataType: "json",
			data:$('#searchForm').serialize()+getCurrentPage(common_list_url+"?"+$('#searchForm').serialize(),10),
	        error: function(){   alert('异常错误'); },
		   success: function(myData){
               $("#dataListTotalCount").text(myData.total);
				var data = baidu.template('dataList',myData);
				$("#myList").html(data);
				  var option= {ele:$("#pageList")[0],total:myData.total,fn:getTableData,url:common_list_url+"?"+$('#searchForm').serialize()}
				generatePages(option);
			   }
			});
  }


function toAdd(){
	$('#my_modal').modal('show');
    //$(".createTime").val(new Date().getTime());
    $("#addForm").find("input[name='formName']").val("addForm");
    $("#addForm").find("select[name='viewType']").val("");
	setToken();
}
//弹框条目明细框
function itemTrees(code,cname,viewType){
    $("#form_cateEname").val(code);
    $("#data-cname").text(cname);
    var index_load = layer.load(1, {shade: false});
    mytools.cleanData("#searchItemForm");
    $("#searchItemForm").find("input[name='viewType']").val(viewType);
    getDataItems();
}
//科目数据明细
function getDataItems(){
    var index_load = layer.load(1, {shade: false});
    $.ajax({url:common_list_url,async:false,type: "get",
        data:$('#searchItemForm').serialize(),dataType: "json",
        success: function(myData){
            //console.log(myData);
            layer.close(index_load);
            myData.viewType = $("#searchItemForm").find("input[name='viewType']").val();
            var data = baidu.template('dataItemList',myData);
            // alert(data);
            $("#dictItmes_body").html(data);
            $('#my_modal_dictItem_view').modal('show');
            $('#dictItmes_body').on('click','tr', function (e) {
                if ( $(this).hasClass('selected') ) {
                    //$(this).removeClass('selected');
                }else {
                    $('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
                itemId = $('tr.selected th').eq(0).html();
            } );
        }
    });
}

function toEdit(cateEname,cateId){
    $.ajax(
        {   type:'get',
            url:common_info_url,
            dataType:'json',
            // data:{'cateId':id,'doCode':'dictCateInfo'},
            data:{'pageName':'dict-list','formName':'searchForm','dictDataCate.w_cateId':cateId},
            success: function(myData){
                // FormUtil.fillData("#addForm", myData,"id");
                FormUtil.loadView("dictDataCate", myData.dictDataCate);
                DictUtil.checkRadioDict("dictDataCate.cateStatus", myData.dictDataCate.cateStatus);
                $("#addForm").find("input[name='formName']").val("editForm");
                $("#addForm").find("select[name='dictDataCate.viewType']").val(myData.dictDataCate.viewType);
                $('#my_modal').modal('show');
                setToken();
            }
        });
    //$('#my_modal').modal('show');
}

function del(cateEname,cateId){
    layer.confirm('您确认要删除['+cateEname+']操作？', { btn: ['确认','取消'] },
        function(){
            $.ajax({type:'post', url:common_submit_url, dataType:'json',
                data:{'pageName':'dict-list','formName':'delForm','dictDataCate.w_cateId':cateId,'dictDataCate.w_cateEname':cateEname},
                success: function(myData){
                    console.log("dictCateDel",myData);
                    if(myData.flag=='T'){
                        layer.alert('删除['+cateEname+']操作成功！');
                        createDictJsFile("1","","");
                        refresh();
                    }else{
                        layer.alert('操作失败！'+myData.msg);
                    }
                }
            });
        },
        function(){}
    );
}
function save(formId){
	if(!$("#" + formId)[0].checkValidity()){
        layer.alert("请先完善必填项！");
		return ;
	}
    var index_submit = layer.confirm("您确定要保存信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
        , function(){
            layer.close(index_submit);
            $.ajax({ type:'post',
                url:common_submit_url,
                dataType:'json',
                data:$("#"+formId).serialize(),
                success: function(myData){
                    //console.log(myData);
                    if(myData.flag=='T'){
                        $('#my_modal').modal('hide');
                        createDictJsFile("1","","");
                        refresh();
                    }else{
                        layer.alert(myData.msg);
                    }
                }
            });
        });
}

function createDictJsFile(flag,cateEname,viewType) {
    var urlAddr = "${ctx}/common/coding/";
    var paramData={};
    paramData["sysEname"]=defSysEname;
    if(flag=="1"){
        urlAddr+="createDictCateList";
	}else{
        urlAddr+="createDictCateItemList";
        paramData["cateEname"]=cateEname;
        paramData["viewType"]=viewType;
    }
    $.ajax({ type:'post', url:urlAddr,dataType:'json',
        data:paramData,
        success: function(myData){
            console.log("createDictJsFile",myData);
            //layer.alert(myData.msg);
        }
    });
}

function cannel(){
	$('#my_modal').modal('hide');

}
function deleteAllRow(){
	var tb = document.getElementById('example');
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}

function refresh(){
    //window.location.reload();
	getTableData();
}
function setToken(){
	$.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',dataType:'text',
	    success: function(myData){
		   $('.formToken').val(myData);
	  	}
	});
}

function toItemEdit(itemId,itemValue){
    setToken();
    mytools.cleanData("#dataItemForm");
    var index_load = layer.load(1, {shade: false});
    $.ajax({type:'get',url:common_info_url,
        data:{"pageName":"dict-list-default","formName":"searchItemForm","dictDataItem.w_itemId":itemId},
        dataType:'json',
        success: function(myData){
        	layer.close(index_load);
        	if(myData){
                FormUtil.loadView("dictDataItem", myData.dictDataItem);
                $("#dataItemForm").find("input[name='formName']").val("editItemForm");
                $("#span_dataItemForm_father_title").text("[修改条目："+itemValue+"]");
                $('#my_modal_item').modal('show');
			}
        }
    });
}
function toItemAdd(){
    setToken();
    $("#span_dataItemForm_father_title").text("");
    mytools.cleanData("#dataItemForm");
    $("#dataItemForm").find("input[name='formName']").val("addItemForm");
    $("#dataItemForm").find("input[name='dictDataItem.treeLevel']").val("1");
    $("#span_dataItemForm_father_title").text("[新增]");
    $("#data-fatherId").val(0);
    $("#data-cateEname").val($("#form_cateEname").val());
    $('#my_modal_item').modal('show');
}
function toSubItemAdd(itemId,itemText,fullEname){
    setToken();
    var count = 1;
    if(fullEname){
        var ss = fullEname.split("/");
        count = ss.length;
	}
    mytools.cleanData("#dataItemForm");
    $("#dataItemForm").find("input[name='formName']").val("addItemForm");
    $("#dataItemForm").find("input[name='dictDataItem.treeLevel']").val(count);
    $("#span_dataItemForm_father_title").text("[上级条目："+itemText+"]");
    $("#data-fatherId").val(itemId);
    $("#data-cateEname").val($("#form_cateEname").val());
    $('#my_modal_item').modal('show');
}
function saveItem(formId){
    if(!$("#" + formId)[0].checkValidity()){
        alert("请先完善必输项和必选项！");
        return ;
    }
    var cateEname = $("#searchItemForm").find("input[name='dictDataItem.w_cateEname']").val();
    var viewType = $("#searchItemForm").find("input[name='viewType']").val();
    var index_submit = layer.confirm("您确定要保存信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
        , function(){
            layer.close(index_submit);
            $.ajax({ type:'post',url:common_submit_url,
                data:$("#"+formId).serialize(), dataType:'json',
                success: function(myData){
                    //console.log(myData);
                    if(myData.flag=='T'){
                        layer.alert('操作成功！', {skin:'layui-layer-molv',closeBtn:0});
                        $('#my_modal_item').modal('hide');
                        createDictJsFile("2",cateEname,viewType);
                        getDataItems();
                    }else{alert(myData.msg);}
                }
            });
    })
}

function getChildTableData(id,treeLevel,obj){
    var count =0;
    var ss = treeLevel.split("/");
    count = ss.length-1;
    var cateNamestr=$("#form_cateEname").val();
    $.ajax({
        type:'get',
        url:common_list_url,
		data:{"pageName":"dict-list-default","formName":"searchItemForm","dictDataItem.w_cateEname":cateNamestr,"dictDataItem.w_fatherId":id},
        //data:{'id':id,"cateEname":cateNamestr,'doCode':'dictItemList'},
        dataType:'json',
        success: function(myData){
            myData.viewType = $("#searchItemForm").find("input[name='viewType']").val();
            var data = baidu.template('dataItemList',myData);
            if($(obj).hasClass("fa-folder-open")){
                $(obj).attr("class","fa fa-folder");
                delChiled(id);
            }else{
                $(obj).attr("class","fa fa-folder-open");
                $("#"+id).after(data);
                $("[fatherid='"+id+"']").each(function(i){
                    var thisObj = $(this);
                    var pd = "10px 20px 10px ";
                    var num = pd+(count*20)+"px";
                    $(thisObj).find("td").eq(0).css("padding",num);
                });
            }
        }
    });
}
function delChiled(id){
    $("[fatherid='"+id+"']").each(function(i){
        var thisObj = $(this);
        $(thisObj).remove();
        var id = thisObj.attr("id");
        delChiled(id);
    });

}
function delItem(itemId,cateEname,itemValue,fatherId){
    layer.confirm('您确认要删除['+itemValue+']操作吗？', { btn: ['确认','取消'] },
        function(){
            $.ajax({type:'post',url:common_submit_url,
                data:{"pageName":"dict-list-default","formName":"delItemForm","dictDataItem.w_cateEname":cateEname,"dictDataItem.w_itemId":itemId,"dictDataItem.w_fatherId":fatherId},
                dataType:'json',
                success: function(myData){
                    if(myData.flag=='T'){
                        layer.alert('删除['+itemValue+']操作成功！', {skin: 'layui-layer-molv',closeBtn: 0 });
                        getDataItems();
                    }else{
                        layer.alert(myData.msg);
					}
                }
            });
        },
        function(){}
    );
}

</script>



	</div>

</div>
</body>








  <!-- foot start -->

  <%@include file="/common/plateform/foot.jsp" %>
  <!-- foot start -->

</html>
